package cn.itsource.ymcc.feign.factory;

import cn.itsource.ymcc.dto.CourseDocumentDto;
import cn.itsource.ymcc.exception.GlobalException;
import cn.itsource.ymcc.feign.client.CourseSearchFeignClient;
import cn.itsource.ymcc.result.JSONResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CourseSearchFeignFallbackFactory implements FallbackFactory<CourseSearchFeignClient> {

    @Override
    public CourseSearchFeignClient create(Throwable throwable) {
        throwable.printStackTrace();
        return new CourseSearchFeignClient() {
            @Override
            public JSONResult courseOnline(CourseDocumentDto courseDocumentDto) {
                log.info("课程ES操作失败："+ courseDocumentDto);
                return JSONResult.error(new GlobalException("课程ES操作失败"+courseDocumentDto.getId()));
            }
        };
    }
}
